﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Z1029.NoteGlobalView
{
    public class NoteSetter : MonoBehaviour
    {
        public NoteType targetSetType;
        public Note.Direction direction;
        public float PosX;
        public float Speed;
        [Tooltip("几分之一拍一个note（自动取整）")] public int setNoteRoundBeat;
        [Tooltip("如果是Hold需要设置")] public int holdTime;
        public int judgelineIndex;
        float lastTime;
        public KeyCode GenerateKey;
        public KeyCode continuedGenerateKey;

        public Note GenerateNote(NoteEditor.Note note)
        {
            Note.NoteData data = new Note.NoteData();
            data.type = (NoteType)note.type;
            data.positionX = note.noteData.positionX;
            data.speed = note.noteData.speed;
            data.beatTime = note.noteData.beatTime;
            data.beatHoldTime = note.noteData.beatHoldTime;
            return LevelController.instance.notesManager.InstantiateNote((NoteType)note.type, data, JudgementLine.selectedJudgeline, (Note.Direction)note.direction);
        }

        void Update()
        {/*
            if (Input.GetMouseButton(0))
            {
                PosX = TransformUtils.GetLocalPosition(Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 8)), LevelController.instance.judgelines[judgelineIndex].transform).x;
            }
            if (Input.GetKeyDown(GenerateKey))
            {
                Note.NoteData data = new Note.NoteData();
                data.type = targetSetType;
                data.positionX = PosX;
                data.speed = Speed;
                data.beatTime = Mathf.RoundToInt(LevelController.instance.NowBeatTime / setNoteRoundBeat) * setNoteRoundBeat;
                data.beatHoldTime = holdTime;
                LevelController.instance.notesManager.InstantiateNote(targetSetType, data, LevelController.instance.judgelines[judgelineIndex], direction);
            }
            if (Input.GetKey(continuedGenerateKey) && Mathf.RoundToInt(LevelController.instance.NowBeatTime / setNoteRoundBeat) * setNoteRoundBeat - lastTime > 1 / 32 * setNoteRoundBeat)
            {
                Note.NoteData data = new Note.NoteData();
                data.type = targetSetType;
                data.positionX = PosX;
                data.speed = Speed;
                data.beatTime = Mathf.RoundToInt(LevelController.instance.NowBeatTime / setNoteRoundBeat) * setNoteRoundBeat;
                data.beatHoldTime = holdTime;
                lastTime = data.beatTime;
                LevelController.instance.notesManager.InstantiateNote(targetSetType, data, LevelController.instance.judgelines[judgelineIndex], direction);
            }*/
        }
    }
}